home *** CD-ROM | disk | FTP | other *** search
/ Computer Select (Limited Edition) / Computer Select.iso / pcc / v04n09 / timer.c < prev    next >
C/C++ Source or Header  |  1990-01-02  |  2KB  |  83 lines

  1. /*
  2. **  TIMER.C
  3. **
  4. **  Program to wait a specified number of minutes
  5. **    (tabstops=4)
  6. **
  7. **  Written for my buddy THR by SCB on 1/2/90
  8. */
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <time.h>
  13. #include <conio.h>
  14. #include <dos.h>
  15.  
  16. void main (
  17.     int argc,
  18.     char *argv[]
  19.     )
  20. {
  21.     register int i;                /* busy ticker index */
  22.     double d;                    /* work double */
  23.     clock_t ticks;                /* target tick count */
  24.     time_t now;                    /* current time */
  25.     int rc;                        /* return code */
  26.     static char busy[] = "/\304\\\263";        /* busy ticker characters */
  27.  
  28.     if (argc != 2) {                        /* pretty inflexible arguments */
  29.         printf("usage: timer <number-of-minutes>\n");
  30.         printf("       returns 0=completed, 1=aborted, 2=error\n");
  31.         exit(2);
  32.         }
  33.  
  34.     if ((ticks = (clock_t)atoi(argv[1])) <= 0) {    /* can't go backwards */
  35.         printf("number-of-minutes must be > 0\n");
  36.         exit(2);
  37.         }
  38.  
  39.     /* dedication */
  40.     printf("\304\304\264 For THR from SCB \303\304\304\n");
  41.  
  42.     d = (double)ticks * 60.0 * CLK_TCK;        /* number of ticks */
  43.  
  44.     time(&now);                                /* output current time */
  45.     printf("\n%s\n",ctime(&now));
  46.  
  47.     printf("Delaying %ld minute%s ... press ESCape to abort   ",
  48.         (long)ticks,(ticks == 1? "": "s"));
  49.  
  50.     ticks = (clock_t)d + clock();            /* target ticks */
  51.  
  52.     rc = 0;                                    /* success return */
  53.     i = 0;                                    /* for busy ticker */
  54.  
  55.     /* loop until abort or target time reached */
  56.  
  57.     while (clock() < ticks) {
  58.  
  59.         if (kbhit())
  60.             if (getch() == 27) {
  61.                 rc = 1;                        /* set aborted return */
  62.                 break;
  63.                 }
  64.  
  65.         putchar(busy[i]);                    /* keep their eyes busy */
  66.         putchar('\010');
  67.  
  68.         if (++i == 4)                        /* advance index */
  69.             i = 0;
  70.  
  71.         sleep(1);                            /* at one second intervals */
  72.         }
  73.  
  74.     if (rc)                                    /* inform of abort */
  75.         printf("  \nAborted with ESCape");
  76.  
  77.     time(&now);
  78.     printf("  \n\n%s",ctime(&now));
  79.  
  80.     exit(rc);
  81.     }
  82.  
  83.